@extends('layouts.mobile_main')

@section('title', '买单')

@section('resources')
    @parent
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" href="{{ env('CSS_DOMAIN') }}css/public.css?v={{env('CSS_VERSION')}}">
    <script src="{{ env('JS_DOMAIN') }}/js/adaptation.js?v={{env('JS_VERSION')}}"></script>
@endsection
<style>
	.pay_shopintop{width: 100%;height: 1.32rem;border-bottom: 1px solid #9955c6;}
	.pay_shopintop img{width: 0.6rem;height: 0.6rem;}
	.pay_shopintop a{position: absolute;top: 0.36rem;left: 0.6rem;}
	.pay_shopintop p{line-height: 1.32rem;text-align: center;}
	.pay_shop_location{font-size: 0.34rem;color: #7f7f7f;text-align: center;padding: 0.3rem 0;}
	.pay_shop_center{width: 100%;background: #eee;}
	.pay_money{width: 9.6rem;margin: 0 0.6rem;background-color: #fff;border-radius: 0.15rem;padding-top: 1.3rem;}
	.pay_money p:nth-child(2){border-bottom: 1px solid #9955c6;padding-bottom: 0.6rem;}
	.pay_money p:nth-child(2) input{height: 1.5rem;text-align: center;font-size: 1rem;width: 100%;}
	.pay_money p:nth-child(3){width: 6.5rem;margin: 0 auto;padding: 0.3rem 0;text-align: center;}
	.pay_money_btn{width: 9.6rem;height: 1.4rem;text-align: center;line-height: 1.4rem;margin: 0.6rem;background-color: #9955c6;color: #fff;font-size: 0.46rem;border-radius: 0.2rem;}
    .pay_sure_background{width: 100%;background: rgba(0,0,0,0.5);position: fixed;top: 0;left: 0;display: none;}
    .pay_sure_shopin{width: 8rem;position: fixed;top: 5rem;left: 50%;margin-left: -4rem;background-color: #fff;border-radius: 0.2rem;}
    .pay_sure_shopin .pay_sure_title{font-size: 0.48rem;text-align: center;color: #4d4d4d;padding: 0.4rem 0;border-bottom: 1px solid #ccc;}
    .pay_sure_shopin .pay_sure_shopname{color: #666;overflow: hidden;margin: 0.2rem 0.6rem;font-size: 0.46rem;}
    .pay_sure_shopin .pay_sure_shopin_money{font-size: 0.58rem;text-align: center;color: #666;}
    #pay_sure_money{color: #9955c6;}
    .pay_sure_shopin_btn{border-top: 1px solid #ccc;font-size: 0.48rem;overflow: hidden;}
    .pay_sure_shopin_btn span{float: left;width: 3.98rem;text-align: center;height: 1.2rem;line-height: 1.2rem;}
    .pay_sure_shopin_btn .pay_sure_shopin_cancel{border-right: 1px solid #ccc;}
</style>
@section('content')
<body>
	<header class="pay_shopintop">
    	<a class="fl" href="javascript:history.go(-1);">
    	    <img class="fl shop_back" src="{{env('IMAGE_DOMAIN')}}images/back_p.png?v={{env('IMAGE_VERSION')}}" alt="">
    	</a>
    	<p class="co_violet fz_50">{{$shopname}}</p>
    </header>
	<section class="pay_shop_center">
		<p class="pay_shop_location">{{$address}}</p>
		<div class="pay_money">
		    <input type="hidden" name="shopid" value="{{$shopid}}" />
			<p>
				<input type="tel" name="money" value="">
			</p>
			<p class="co_violet fz_34">{{$payinfo}}</p>
		</div>
		<p class="pay_money_btn">已和店员确认金额 立即买单</p>
	</section>
    <!-- 使用红包 -->
    <nav class="pay_sure_background">
        <div class="pay_sure_shopin">
            <p class="pay_sure_title">确认支付</p>
            <p class="pay_sure_shopname fz_44" style="margin-top: 0.5rem;">
                <span class="fl">消费金额：</span>
                <span class="fr" id="orderamount"></span>
            </p>
            <p class="pay_sure_shopname fz_44">
                <span class="fl">红包：</span>
                <span class="fr" id="redenvelopeamount"></span>
            </p>
            <p class="pay_sure_shopname" style="margin-top: 0.6rem;color: #9955c6;margin-bottom: 0.4rem;">
                <span class="fl">本次消费实付金额：</span>
                <span class="fr" style="font-size: 0.6rem;" id="actualamount"></span>
            </p>
            <p class="pay_sure_shopin_btn">
                <span class="pay_sure_shopin_cancel">取消</span>
                <span class="pay_sure_shopin_sure">确认</span>
            </p>
        </div>
    </nav>
@endsection

@section('scriptResources')
    @parent
    <script>
	    window.onresize=function(){
		    pagesp();
	    }
	    $(function(){
	    	$("input").focus();
		    var pay_outer_h=$(window).height()-$('.pay_shopintop').height()-1;
		    $(".pay_shop_center").css({"min-height":pay_outer_h});
	    })
        $(".pay_sure_background").height($(window).height());
	    $(".pay_money_btn").click(function() {
	        var shopid = $("input[name='shopid']").val();
	        var money = $("input[name='money']").val();
            if(money == 0||money == ""){
                alert("请输入金额");return;
            }else{
                $.ajax({
                     url: '/mobile/wallet/pay/redenvelopeamount/get',
                     type: 'get',
                     data:{'money':money},
                     dataType: 'json',
                     async: false,
                     success:function(data){
                         if (data.status == "success") {
                            var data = data.data;
                            $("#orderamount").html(money);
                            $("#redenvelopeamount").html(data.redenvelopeamount);
                            $("#actualamount").html(data.actualamount);
                            $(".pay_sure_background").show();
                         } else {
                             alert(data.message);
                         }
                     }
                })
                            
            }
	    });
        $(".pay_sure_shopin_sure").click(function(){
            var shopid = $("input[name='shopid']").val();
            var money = $("input[name='money']").val();
            $.ajax({
                url :"/mobile/wallet/pay/shopin/result",
                type:'POST',
                data : {'shopid':shopid, 'money':money},
                dataType:'json',
                async:false,
                success:function(data){
                    if (data.status == "success") {
                        var data = data.data;
                        var orderNumber = data.ordernumber;
                        var status = data.status;
                        if(status == '2') {
                            //买单成功
                            window.location.href="/mobile/wallet/pay/end?ordernumber=" + orderNumber;
                        } else if(status == '1') {
                            //余额不足
                            window.location.href="/mobile/wallet/recharge";
                        } else if(status == '3') {
                            //超过次数
                            alert("你在本店买单次数已用完");
                        } else if(status == '4') {
                            window.location.href='/mobile/wallet/pay/shopin/password?shopid='+shopid+"&money="+money;
                        }

                    } else {
                        alert(data.message);
                    }
                }
            });
        })
        // $("pay_sure_shopin_cancel").on("")
        $(".pay_sure_shopin_cancel").click(function(){
            $(".pay_sure_background").hide();
        })
    </script>
@endsection